const Mock = require('mockjs');
const data = Mock.mock({
    'list|11-20': [{
        img: '@image(50x50,@color)',
        title: '@ctitle',
        id: '@id'
    }],
    'goods|10': [{
        img: '@image(100x100,@color)',
        title: '@ctitle(15,25)',
        'price|30-200.2': 0,
        id: '@id'
    }],
    'address|2': [{
        id: '@id',
        name: '@cname',
        tel: /^1[3-9]\d{9}$/,
        province: '@province',
        city: '@city',
        county: '@county',
        isDefault: false //设为默认地址
    }]
})

console.log(data.goods);

module.exports = {
    devServer: {
        before(app) {
            app.get('/list', (req, res) => {
                res.send(data.list)
            })
            app.get('/goods', (req, res) => {
                res.send(data.goods)
            })
            app.get('/goodsDetail', (req, res) => {
                const { id } = req.query
                const newArr = data.goods.filter(item => {
                    return item.id == id
                })
                res.send(newArr[0])
            })
            app.get('/getAddress', (req, res) => {
                res.send(data.address)
            })
        }
    }
}